/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-10-26 14:45:49
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2021-10-26 19:39:11
 * @FilePath: \code\cwp-front\pc-collaboration\src\plugins\directives\modules\focus.js
 * @Description: 自动获取焦点
 */
function autoFocus(el, binding) {
    const { modifiers } = binding;
    //如果是文本域组件，就选中它下一级的文本域框
    const target = modifiers.textarea ? el.firstElementChild : el;
    // 聚焦元素
    target.focus();
}

export default {
    install(Vue) {
        Vue.directive('focus', {
            inserted: autoFocus,
            update: autoFocus,
        });
    },
};
